﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.EntityClient;
using System.Data;


namespace EpiPoker.DataAccess
{
    /// <summary>
    /// Stored Procedures for T_Game Table
    /// </summary>
    public class Game
    {
        #region UpdateDBB

        /// <summary>
        /// Create Game
        /// </summary>
        /// <param name="IdTable">The Table in game</param>
        /// <param name="Serialize">The string serialized of the game</param>
        /// <returns>true if goes well</returns>
        public static bool CreateGame(long IdTable, string Serialize)
        {
            try
            {
                fbPokerEntities model = new fbPokerEntities();
                T_Game game = new T_Game();
                game.date = DateTime.Now;
                game.IdTable = IdTable;
                game.Serialize = Serialize;

                model.AddToT_Game(game);
                model.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        #endregion

        #region GetFromDBB

        /// <summary>
        /// Get the last game created
        /// </summary>
        /// <param name="IdTable">The Table in game</param>
        /// <returns>The game if all goes well</returns>
        public static T_Game GetLastGameForTable(long IdTable)
        {
            try
            {
                using (fbPokerEntities bdd = new fbPokerEntities())
                {
                    return bdd.GetLastGameForTable(IdTable).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        #endregion
    }
}